/**
 * 
 */
package de.uni_leipzig.informatik.asv.unsupervised_pos_tagger.tests;
import static org.junit.Assert.*;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.HashSet;
import java.util.Set;

import org.junit.Before;
import org.junit.Test;

import de.uni_leipzig.informatik.asv.unsupervised_pos_tagger.datacreation.CreateGraph;
import de.uni_leipzig.informatik.asv.unsupervised_pos_tagger.datacreation.FeatureType;
import de.uni_leipzig.informatik.asv.unsupervised_pos_tagger.datacreation.feature_types.CaseFeatures;
import de.uni_leipzig.informatik.asv.unsupervised_pos_tagger.datacreation.feature_types.PunctuationFeatures;
import de.uni_leipzig.informatik.asv.unsupervised_pos_tagger.datacreation.feature_types.SuffixFeatures;
/**
 * @author Christoph Teichmann
 * created Jun 9, 2014 5:37:59 PM
 * @version 0.1
 */
public class TestCreateGraph
{
	/**
	 * 
	 */
	private CreateGraph cg;
	/**
	 *
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception
	{
		FeatureType[] ft = new FeatureType[] {new SuffixFeatures(2),new PunctuationFeatures(),
				new CaseFeatures()};
		cg = new CreateGraph(false, true, ft);
	}
	/**
	 * Test method for {@link de.uni_leipzig.informatik.asv.unsupervised_pos_tagger.datacreation.CreateGraph#addAlignments(java.io.BufferedReader)}.
	 * @throws IOException 
	 */
	@Test
	public final void testAddAlignments() throws IOException
	{
		StringReader sr = new StringReader(TestStrings.ALIGNMENTS);
		BufferedReader br = new BufferedReader(sr);
		cg.addAlignments(br);
		br.close();
		sr = new StringReader(TestStrings.SINGLE);
		br = new BufferedReader(sr);
		StringWriter sw = new StringWriter();
		BufferedWriter bw = new BufferedWriter(sw);
		cg.addSequentialOnly(br);
		br.close();
		cg.writeOutEdges(bw);
		bw.close();
		Set<String> s = new HashSet<>();
		String[] parts = sw.toString().split("\\n");
		for(String st : parts)
		{s.add(st);}
		assertTrue(s.contains("hund|DEUTSCH	lebt|DEUTSCH	FOLLOWING	2"));
		assertTrue(s.contains("live|ENGLISH	lebt|DEUTSCH	TRANSLATE	1"));
	}
	@Test
	public final void testAddAlignmentsArbitrary() throws IOException
	{
		StringReader sr = new StringReader(TestStrings.FREE_ALIGNMENT_STRING);
		BufferedReader br = new BufferedReader(sr);
		cg.addFreeAlignments(br);
		br.close();
		StringWriter sw = new StringWriter();
		BufferedWriter bw = new BufferedWriter(sw);
		cg.writeOutEdges(bw);
		bw.close();
		Set<String> s = new HashSet<>();
		String[] parts = sw.toString().split("\\n");
		for(String st : parts)
		{s.add(st);}
		assertTrue(s.contains(".|English	.|Deutsch	TRANSLATE	2"));
		assertTrue(s.contains("gehts|Deutsch	!|Deutsch	FOLLOWING	1"));
	}
}